package app.server.project.cloud.random.db.entity;

import app.server.project.core.syndb.SynDBMgr;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "user_info")
@TableName("user_info")
@Comment(value = "用户信息表")
public class UserInfoEntity {

    @Id
    @Column(name = "id")
    @Comment("用户主键")
    @TableId("id")
    private long id;

    @TableField("email")
    @Comment("邮箱")
    @Column(name = "email")
    private String email;

    @TableField("create_time")
    @Comment("创建时间")
    @Column(name = "create_time")
    private LocalDateTime createTime;

    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInfoEntity::getCreateTime, this);
    }

    public void setEmail(String email) {
        this.email = email;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInfoEntity::getEmail, this);
    }


}
